/*
 * --------------------------------------------------------------
 * Copyright ©  2015 Hangzhou DtDream Technologies Co.,Ltd.
 * --------------------------------------------------------------
 *      Product: 协同数治
 *  Module Name: design
 * Date Created: 2022/12/15
 *  Description: TODO
 * --------------------------------------------------------------
 * Modification History
 * DATE            NAME            Description
 * --------------------------------------------------------------
 * 2022/12/15       yewj            TODO
 * --------------------------------------------------------------
 */

package com.dtdream.principle.inversion.improve;

/**
 * 实现依赖导致的一些方法
 *
 * @Author: yewj
 **/
public class DependencyInversionSomMethods {
    public static void main(String[] args) {
    }
}


// 方式1：通过接口传递实现依赖
/*interface IOpenAndClose {
    void open(ITV itv);
}

interface ITV {
    void play();
}

class OpenAndClose implements IOpenAndClose {

    @Override
    public void open(ITV itv) {
        itv.play();
    }
}*/

// 方式2：通过构造器依赖传递
/*interface IOpenAndClose {
    void open();
}

interface ITV {
    void play();
}

class OpenAndClose implements IOpenAndClose {

    private ITV itv;

    public OpenAndClose(ITV itv) {
        this.itv = itv;
    }

    @Override
    public void open() {
        itv.play();
    }
}*/

// 方式3：通过setter方式依赖传递
interface IOpenAndClose {
    void open();
}

interface ITV {
    void play();
}

class OpenAndClose implements IOpenAndClose {

    private ITV itv;

    public void setItv(ITV itv) {
        this.itv = itv;
    }

    @Override
    public void open() {
        itv.play();
    }
}
